i2c: bcm2835: Fix hang for writing messages larger than 16 bytes
authorNoralf Trønnes <noralf@tronnes.org>
Sat, 17 Sep 2016 13:07:10 +0000 (15:07 +0200)
committerRaspbian kernel package updater <root@raspbian.org>
Thu, 9 Mar 2017 17:51:56 +0000 (17:51 +0000)
commit99030645593464749d826228febe9e9aac7cad24
treec2ca5be2233d43d88fb64a8126e0a77da686d5e6
parentf3732290e8f16978dd5828e70c2463b67cb07765
i2c: bcm2835: Fix hang for writing messages larger than 16 bytes

Writing messages larger than the FIFO size results in a hang, rendering
the machine unusable. This is because the RXD status flag is set on the
first interrupt which results in bcm2835_drain_rxfifo() stealing bytes
from the buffer. The controller continues to trigger interrupts waiting
for the missing bytes, but bcm2835_fill_txfifo() has none to give.
In this situation wait_for_completion_timeout() apparently is unable to
stop the madness.

The BCM2835 ARM Peripherals datasheet has this to say about the flags:
  TXD: is set when the FIFO has space for at least one byte of data.
  RXD: is set when the FIFO contains at least one byte of data.
  TXW: is set during a write transfer and the FIFO is less than full.
  RXR: is set during a read transfer and the FIFO is or more full.

Implementing the logic from the downstream i2c-bcm2708 driver solved
the hang problem.

Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Martin Sperl <kernel@martin.sperl.org>
drivers/i2c/busses/i2c-bcm2835.c